package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.entity.SmallPageBean;
import com.itheima.pojo.Member;
import com.itheima.pojo.User;
import com.itheima.service.MemberService;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user_manag")
public class UserManagController {

    @Reference
    private UserService userService;

    @RequestMapping("/add")
    public Result add(@RequestBody User user,Integer[] roleIds){
        try {
            userService.add(user,roleIds);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_USER_FAIL);
        }
        return new Result(true,MessageConstant.ADD_USER_SUCCESS);
    }

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return userService.pageQuery(queryPageBean);
    }

    @RequestMapping("/findAll")
    public PageResult findAll(@RequestBody SmallPageBean smallPageBean) {
        //调用方法
        return userService.findAll(smallPageBean);
    }
}
